importPackage(net.sf.odinms.net.channel);
importPackage(net.sf.odinms.client);
importPackage(net.sf.odinms.tools);

var status = 0;
var pqmap = 109010100;
var neededmembers = 6;
var exitmap = 109050000;

function start() {
 status = -1;
 action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode == -1) {
		cm.dispose();
	} else {
		if (mode == 0) {
			cm.sendOk("OK then, see you next time!");
   			cm.dispose();
   			return;
  		}
		if (mode == 1)
   			status++;
  		else
   			status--;
  		if (status == 0) {
			if (cm.getParty() == null) {
				cm.sendOk("You need a party to do the PQ");
				cm.dispose();
			} else if (!cm.isLeader()) {
				cm.sendOk("Let your leader talk to me");
				cm.dispose();
			} else if (cm.getCharQuantity(pqmap) > 0) {
				cm.sendOk("There is already a PQ going on");
				cm.dispose();
			} else {
				if (cm.getPartyMembers() == neededmembers) {
					cm.sendYesNo("Hey, i see you are in a party of #b" + neededmembers + "#k\r\nAnd theres no party in the PQ yet\r\n\r\nDo you wish to do the PQ?");
				} else {
					cm.sendOk("Your party is not a party of #b" + neededmembers + "#k");
					cm.dispose();
				}
			}
		} else {
			cm.warpParty(pqmap);
			cm.startClockTimer(exitmap, 10);
			cm.dispose();
		}
	}
}